<?php
global $bp;

get_header();
$category = attribute_escape( bp_current_action() );
$all_achievements = dpa_get( '*', array( array( 'type' => 'd', 'key' => 'active', 'value' => 1 ), array( 'type' => 's', 'key' => 'category', 'value' => $category ) ) );
if ( bp_is_home() ) { $user_id = $bp->loggedin_user->id; } else { $user_id = $bp->displayed_user->id; }

$earnt  = (int) dpa_count_of_ea( $user_id, $category );
$active = (int) dpa_get( 'COUNT(short_name)', array( array( 'type' => 'd', 'key' => 'active', 'value' => 1 ), array( 'type' => 's', 'key' => 'category', 'value' => $category ), array( 'type' => 's', 'key' => 'category', 'value' => $category ) ) );  // special-case
$percentage = ($earnt / $active) * 100;
?>
<div class="content-header"></div>

<div id="content">
	<?php do_action( 'template_notices' ); // (error/success feedback) ?>

	<div id="dpa">		
		<div id="dpa-graphs">
			<div class="graph fullsize">
				<div class="bar" style="width: <?php echo $percentage; ?>%"></div>
				<div class="caption"><p>Total Completed: <?php echo $earnt; ?> / <?php echo $active; ?></p></div>
			</div>
		</div>

		<?php foreach ( $all_achievements as $achievement ) {
			dpa_detailview( $user_id, $achievement );
		} ?>
	</div>
</div>

<?php get_footer() ?>